﻿using System;
using System.Web.UI;
using MTC.Common;
using MTC.Common.Enum;
using MTC.Web.Business;
using MTC.Web.Business.DTO;

namespace MTC.Web.Forms
{
    public partial class PayInEdit : System.Web.UI.Page
    {
        private PayInEntity _entity;
        Business.PayIns PayInsBO = new Business.PayIns();

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                SetupEnvironment();
                //get the PayIns id if available
                if (Request.Params[Params.PAYINID] != "0")
                {
                    int payInId = Convert.ToInt32(Request.Params[Params.PAYINID]);
                    _entity = PayInsBO.GetAPayIn(payInId);
                    LoadFields();
                }
            }
        }

        private void SetupEnvironment()
        {
        }

        private void LoadFields()
        {
            if (_entity == null)
                return;

        }

        private void ClearFields()
        {
        }

        private bool SetFields()
        {
            PayInEntity entity = new PayInEntity();

            if (hfPayIdId.Value != "")
                entity.PayInId = Convert.ToInt32(hfPayIdId.Value);

            
            if (entity.PayInId == 0)
            {
                PayInsBO.AddPayIn(entity);
            }
            else
            {
                return PayInsBO.UpdateAPayIn(entity);                                
            }
            return true;
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (ValidateFields())
            {
                SetFields();
            }


        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            ClearFields();
            Response.Redirect(Common.Urls.PayInListURL(), true);
        }

        protected bool ValidateFields()
        {
            return true;
        }
    }
}
